#include "addpet.h"
#include "ui_addpet.h"

AddPet::AddPet(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddPet)
{
    ui->setupUi(this);
    sexBtn = new QButtonGroup();
    sexBtn->setExclusive(true);
    sexBtn->addButton(ui->sex_male, 0);
    sexBtn->addButton(ui->sex_female, 1);
}

AddPet::~AddPet()
{
    delete ui;
}

void AddPet::setSQL(SQLConn *& conn)
{
    sql = conn;
}

void AddPet::on_pushButton_2_clicked()
{
    this->close();
}

void AddPet::on_pushButton_clicked()
{
    m_name = ui->le_name->text();
    m_age = ui->sb_age->text().toFloat();
    if (sexBtn->checkedId() == 0)
    {
        m_sex ="男";
    }
    else
    {
        m_sex ="女";
    }
    m_owner_id = ui->le_ownerid->text().toInt();
    m_owner_name = sql->getOwnerName(m_owner_id);
    m_kind = ui->le_kind->text();
    m_status = ui->le_kind->text();
    sql->add_pet(m_name, m_sex, m_age, m_kind, m_owner_id, m_owner_name, m_status);
    this->close();

}
